#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	return x*f;
}
int a[2005],c[2005],n,ans;
void dfs(int x,int las,int Las,int sum)
{
	if(x>n)
	{
		ans=max(ans,sum);
		return;
	}
	if(a[x]!=Las)
	{
		c[x]=1;
		if(a[x]==las) dfs(x+1,a[x],Las,sum+las);
		else dfs(x+1,a[x],Las,sum);
	}
	if(a[x]!=las)
	{
		c[x]=2;
		if(a[x]==Las) dfs(x+1,las,a[x],sum+Las);
		else dfs(x+1,las,a[x],sum);
	}
	c[x]=0;
}
int main()
{
	//freopen     
	//freopen
	//freopen
	//freopen
	//freopen
	//freopen luogu uid 772909
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	int T=read();
	while(T--)
	{
		n=read();
		ans=0;
		memset(c,0,sizeof(c));
		for(int i=1;i<=n;i++)a[i]=read();
		dfs(1,-114,-114,0);
		printf("%d\n",ans);
	}
	return 0;
}
